<?php
namespace app\admin\model;

use think\Controller;
use think\Validate;

#公共验证器#

class ComValidate extends Controller {

	#站点信息验证#
	public function Site_Validate($data){

		$rule = [
		    'name'  => 'require',
		    //'link'  => 'require',
		    'keywords'  => 'require',
		    'description'  => 'require',
		    'logo'  => 'require'

		];

		$msg = [
		    'name.require' => '站点名称必须填写',
		   // 'name.max'     => '站点名称最多不能超过50个字符',
		   // 'link.require' => '站点网址必须填写',
		    'keywords.require' => '站点关键字必须填写',
		    'description.require' => '站点描述必须填写',
		    'logo.require' => '站点logo必须上传'
		];

		$validate = new Validate($rule, $msg);
	
		if(!$validate->check($data)){
			$this->error($validate->getError());
		}

	}

	
	#必填#
	public function data_must($data,$type='text'){
		if(empty($data)){
			switch ($type) {
				case 'text':
					exit("条件错误~");
					break;
				case 'json':
					json(['msg'=>"条件错误~"]);
				break;
				
			}
		}
	}

}